package com.renwei.yunlong.activity.contacts;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.base.BaseActivity;
import com.renwei.yunlong.global.IntentKey;
import com.renwei.yunlong.utils.CommonUtils;
import com.zyf.fwms.commonlibrary.utils.StatusBarUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Project :  yunaandroid.
 * Package name: com.renwei.yunlong.activity
 * Created by :  Benjamin.
 * Created time: 2017/11/13 16:18
 * Changed by :  Benjamin.
 * Changed time: 2017/11/13 16:18
 * Class description:
 */

public class CompanyCertificateTypeActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.tv_business_licence)
    TextView tvBusinessLicence;
    @Bind(R.id.tv_organization_code)
    TextView tvOrganizationCode;
    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    private String typeNum;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_company_certificate_type);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(this, CommonUtils.getColor(this, R.color.title_color), 0);
        typeNum = getIntent().getStringExtra(IntentKey.CERTIFICATET_TYPE) == null ? "1" : getIntent().getStringExtra(IntentKey.CERTIFICATET_TYPE);
        tvTitle.setText("证书类型");
        tvRight.setVisibility(View.GONE);
        ivBack.setOnClickListener(this);
        tvOrganizationCode.setOnClickListener(this);
        tvBusinessLicence.setOnClickListener(this);
        setSelectedItem(typeNum);
    }

    public void setSelectedItem(String item) {
        if ("1".equals(item)) {
            Drawable drawable1 = getResources().getDrawable(R.mipmap.choosen);
            drawable1.setBounds(0, 0, drawable1.getMinimumWidth(), drawable1.getMinimumHeight()); //设置边界
            tvBusinessLicence.setCompoundDrawables(null, null, drawable1, null);//画在右边
            Drawable drawable2 = getResources().getDrawable(R.mipmap.choosen);
            drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight()); //设置边界
            tvOrganizationCode.setCompoundDrawables(null, null, null, null);//画在右边
        } else {
            Drawable drawable1 = getResources().getDrawable(R.mipmap.choosen);
            drawable1.setBounds(0, 0, drawable1.getMinimumWidth(), drawable1.getMinimumHeight()); //设置边界
            tvOrganizationCode.setCompoundDrawables(null, null, drawable1, null);//画在右边
            Drawable drawable2 = getResources().getDrawable(R.mipmap.choosen);
            drawable2.setBounds(0, 0, drawable2.getMinimumWidth(), drawable2.getMinimumHeight()); //设置边界
            tvBusinessLicence.setCompoundDrawables(null, null, null, null);//画在右边
        }
    }

    @Override
    public void onClick(View view) {
        Intent data = new Intent();
        switch (view.getId()) {
            case R.id.tv_business_licence:
                typeNum = "1";
                setSelectedItem(typeNum);
                data.putExtra(IntentKey.CONTENT, typeNum);
                setResult(IntentKey.CERTIFICATET_TYPE_KEY, data);
                this.finish();
                break;
            case R.id.tv_organization_code:
                typeNum = "2";
                setSelectedItem(typeNum);
                data.putExtra(IntentKey.CONTENT, typeNum);
                setResult(IntentKey.CERTIFICATET_TYPE_KEY, data);
                this.finish();
                break;
            case R.id.iv_back:
                this.finish();
                break;
            default:
                break;
        }
    }
}
